/*
********************************************************************************
* Copyright (C) 2021, xiang.D <dx_65535@163.com>.
* All right reserved.
*
* File Name   : led.h
* Author      :
* Version     : V1.0
* Description :
* Journal     : 2021-01-15 init v1.0
* Brief       : Blog: https://blog.csdn.net/qq_38750572?spm=1001.2014.3001.5343
* Others      :
********************************************************************************
*/
#ifndef __LED_H__
#define __LED_H__

typedef enum
{
    LED_BUSY = 0,
    LED_IDLE
} ELedStatus;

typedef enum
{
    LED_SHARED = 0,
    LED_UNSHARED            ///< Power Led
} EPermission;

typedef enum
{
    LED_MODE_DEFAULT = 0,   ///< Default Mode
    LED_MODE_HORSE ,        ///< Horse Led Mode
    LED_MODE_BREATH         ///< Breath Led Mode
} EUsedMode;

#define MAX_SHARED_LED 2

class CLed
{
public:
    CLed () {}
    virtual ~CLed() {}
    void SetStatus(ELedStatus status);
    ELedStatus  GetStatus();
    void SetUsedMode(EUsedMode mode);
    EUsedMode  GetUsedMode();
    void SetPermission(EPermission permission);
    EPermission  GetPermission();
    void SetFrequency(int freq);
    void SetIndex(int value);
    void UpdateLed(EPermission permission, EUsedMode mode, int freq);
    virtual void Start();
    virtual void Stop();
    virtual void Relase();

private:
    int         mIndex;
    int         mFreq;
    ELedStatus  mStatus;
    EUsedMode   mUsedMode;
    EPermission mPermission;
};

// 共享Led计数
static int shared_led = -1;

class CSharedLed : public CLed
{
public:
    CSharedLed()
    {
        shared_led ++;
        SetIndex(shared_led);            ///< 用于绑定具体的Led资源
    }

    ~CSharedLed()
    {

    }
};

// Led used for showing power status
class CUnsharedLed : public CLed
{
public:
    explicit CUnsharedLed(EPermission permission)
    {
        SetStatus(LED_IDLE);
        SetPermission(permission);
    }

    // Power Led 只创建一个实例
    static CUnsharedLed* GetInstance()
    {
        static CUnsharedLed obj(LED_UNSHARED);
        return &obj;
    }

    void Start();

    void Stop();

    void Relase();

private:
    ~CUnsharedLed()
    {

    }
};

#endif
